<template>
  <el-container class="home-container" style="height: 950px">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <img src="../assets/icon/headerIcon.jpg" alt="" style="width: 50px; border-radius: 25%"/>
        <span>会议室预定系统</span>
      </div>


      <div class="header-avatar">
          <el-avatar src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"></el-avatar>
          <el-dropdown>
            <span class="el-dropdown-link">
              {{queryUser.username}}
              <i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="toUserCenter">
                个人中心
              </el-dropdown-item>
              <el-dropdown-item @click.native="logout">退出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
      </div>

    </el-header>
    <!-- 页面主体区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <!-- 侧边栏菜单区域 -->
        <el-menu :default-active="activePath" :router="true" :collapse-transition="false" :collapse="isCollapse" background-color="#333744" text-color="#fff" active-text-color="#409eff">
          <!-- 一级菜单 -->
          <el-submenu :index="item.id + ''" v-for="item in menulist" :key="item.id" >
            <!-- 一级菜单的模板 -->
            <template slot="title">
              <!-- 图标 -->
              <i :class="iconsObj[item.id]"></i>
              <!-- 文本 -->
              <span>{{ item.authName }}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item @click="saveNavState('/' + subItem.path)" :index="'/' + subItem.path" v-for="subItem in item.children" :key="subItem.id">
              <template slot="title">
                <!-- 图标 -->
                <i :class="iconsObj[subItem.id]"></i>
                <!-- 文本 -->
                <span>{{ subItem.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧内容 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      queryUser: {
        id: "",
        username: "用户"
      },
      menulist: [
        {
          id: 101,
          authName: "会议室预定/签到",
          path: "null",
          children: [
            { id: 1011, authName: "快速预定", path: "quickBook" },
            { id: 1013, authName: "签到和取消", path: "cancelBook" },
          ],
        },
        {
          id: 102,
          authName: "预定进程/历史",
          path: "null",
          children: [
            { id: 1021, authName: "查看当前预定", path: "currentRecord" },
            { id: 1022, authName: "查看历史预定", path: "historyRecord" },
            { id: 1023, authName: "查看违规预定", path: "violateRecord" },
          ],
        },
        {
          id: 103,
          authName: "会议室查询",
          path: "null",
          children: [
            { id: 1031, authName: "所有会议室", path: "AllRoom" },
            { id: 1032, authName: "空闲会议室", path: "AvailableRoom" },
          ],
        },
      ],
      iconsObj: {
        101: "el-icon-user-solid",
        102: "el-icon-thumb",
        103: "el-icon-search",
        1011: "el-icon-s-promotion",
        1012: "el-icon-circle-plus",
        1013: "el-icon-error",
        1014: "el-icon-s-claim",
        1021: "el-icon-folder-checked",
        1022: "el-icon-document-copy",
        1023: "el-icon-warning-outline",
        1031: "el-icon-s-unfold",
        1032: "el-icon-circle-check"
      },
      isCollapse: false,
      activePath: "",
    };
  },
  methods: {
    logout() {
      window.sessionStorage.clear()
      this.$router.push("/")
    },

    toUserCenter() {
      this.$router.push('/userCenter')
    },

    //点击按钮，切换菜单的折叠与展开
    toggleCollapse() {
      this.isCollapse = !this.isCollapse
    },

    saveNavState (activePath) {
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    }
  },

  created() {
    this.queryUser.username = window.sessionStorage.getItem('username')
    this.activePath = window.sessionStorage.getItem('activePath')
    // console.log(this.activePath)
    //if(this.$route.path == '/welcome') this.activePath = ''
  }
};
</script>

<style lang="scss" scoped>
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 3px;
  align-items: center;
  color: #fff;
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
    }
  }
}

.el-aside {
  background-color: #333744;
}

.el-main {
  background-color: #eaedf1;
}

.el-menu {
  border-right: 0;
}

.toggle-button {
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #ffffff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
  transition: 0.6s;
}

.header-avatar{
  float: right;
  width: 150px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409EFF;
}

</style>
